home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / fax / src / libtiff / tiffiop.h < prev   
C/C++ Source or Header  |  1994-08-01  |  15KB  |  427 lines

  1. /* $Header: /usr/people/sam/tiff/libtiff/RCS/tiffiop.h,v 1.39 93/02/03 16:57:02 sam Rel $ */
  2.  
  3. /*
  4.  * Copyright (c) 1988, 1989, 1990, 1991, 1992 Sam Leffler
  5.  * Copyright (c) 1991, 1992 Silicon Graphics, Inc.
  6.  *
  7.  * Permission to use, copy, modify, distribute, and sell this software and 
  8.  * its documentation for any purpose is hereby granted without fee, provided
  9.  * that (i) the above copyright notices and this permission notice appear in
  10.  * all copies of the software and related documentation, and (ii) the names of
  11.  * Sam Leffler and Silicon Graphics may not be used in any advertising or
  12.  * publicity relating to the software without the specific, prior written
  13.  * permission of Sam Leffler and Silicon Graphics.
  14.  * 
  15.  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
  16.  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
  17.  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
  18.  * 
  19.  * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
  20.  * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
  21.  * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  22.  * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF 
  23.  * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 
  24.  * OF THIS SOFTWARE.
  25.  */
  26.  
  27. #ifndef _TIFFIOP_
  28. #define    _TIFFIOP_
  29. /*
  30.  * ``Library-private'' definitions.
  31.  */
  32. #include "tiffconf.h"
  33. #include "tiffcomp.h"
  34. #include "tiffio.h"
  35.  
  36. /*
  37.  * Internal format of a TIFF directory entry.
  38.  */
  39. typedef    struct {
  40. #define    FIELD_SETLONGS    2
  41.     /* bit vector of fields that are set */
  42.     u_long    td_fieldsset[FIELD_SETLONGS];
  43.  
  44.     u_long    td_imagewidth, td_imagelength, td_imagedepth;
  45.     u_long    td_tilewidth, td_tilelength, td_tiledepth;
  46.     u_short    td_subfiletype;
  47.     u_short    td_bitspersample;
  48.     u_short    td_sampleformat;
  49.     u_short    td_compression;
  50.     u_short    td_photometric;
  51.     u_short    td_threshholding;
  52.     u_short    td_fillorder;
  53.     u_short    td_orientation;
  54.     u_short    td_samplesperpixel;
  55.     u_short    td_predictor;
  56.     u_long    td_rowsperstrip;
  57.     u_long    td_minsamplevalue, td_maxsamplevalue;    /* XXX */
  58.     float    td_xresolution, td_yresolution;
  59.     u_short    td_resolutionunit;
  60.     u_short    td_planarconfig;
  61.     float    td_xposition, td_yposition;
  62.     u_long    td_group3options;
  63.     u_long    td_group4options;
  64.     u_short    td_pagenumber[2];
  65.     u_short    td_matteing;
  66.     u_short    td_cleanfaxdata;
  67.     u_short    td_badfaxrun;
  68.     u_long    td_badfaxlines;
  69.     u_short    *td_colormap[3];
  70.     u_short    td_halftonehints[2];
  71.     char    *td_documentname;
  72.     char    *td_artist;
  73.     char    *td_datetime;
  74.     char    *td_hostcomputer;
  75.     char    *td_imagedescription;
  76.     char    *td_make;
  77.     char    *td_model;
  78.     char    *td_software;
  79.     char    *td_pagename;
  80.     u_long    td_stripsperimage;
  81.     u_long    td_nstrips;        /* size of offset & bytecount arrays */
  82.     u_long    *td_stripoffset;
  83.     u_long    *td_stripbytecount;
  84. #ifdef YCBCR_SUPPORT
  85.     float    *td_ycbcrcoeffs;
  86.     u_short    td_ycbcrsubsampling[2];
  87.     u_short    td_ycbcrpositioning;
  88. #endif
  89. #ifdef JPEG_SUPPORT
  90.     u_short    td_jpegproc;
  91.     u_short    td_jpegrestartinterval;
  92.     u_char    **td_qtab;
  93.     u_char    **td_dctab;
  94.     u_char    **td_actab;
  95. #endif
  96. #ifdef COLORIMETRY_SUPPORT
  97.     float    *td_whitepoint;
  98.     float    *td_primarychromas;
  99.     float    *td_refblackwhite;
  100.     u_short    *td_transferfunction[3];
  101. #endif
  102. #ifdef CMYK_SUPPORT
  103.     u_short    td_inkset;
  104.     u_short    td_dotrange[2];
  105.     char    *td_inknames;
  106.     char    *td_targetprinter;
  107. #endif
  108. } TIFFDirectory;
  109.  
  110. /*
  111.  * Field flags used to indicate fields that have
  112.  * been set in a directory, and to reference fields
  113.  * when manipulating a directory.
  114.  */
  115. /* multi-entry fields */
  116. #define    FIELD_IMAGEDIMENSIONS        0
  117. #define FIELD_TILEDIMENSIONS        1
  118. #define    FIELD_CELLDIMENSIONS        2        /* XXX */
  119. #define    FIELD_RESOLUTION        3
  120. #define    FIELD_POSITION            4
  121. /* single-entry fields */
  122. #define    FIELD_SUBFILETYPE        5
  123. #define    FIELD_BITSPERSAMPLE        6
  124. #define    FIELD_COMPRESSION        7
  125. #define    FIELD_PHOTOMETRIC        8
  126. #define    FIELD_THRESHHOLDING        9
  127. #define    FIELD_FILLORDER            10
  128. #define    FIELD_DOCUMENTNAME        11
  129. #define    FIELD_IMAGEDESCRIPTION        12
  130. #define    FIELD_MAKE            13
  131. #define    FIELD_MODEL            14
  132. #define    FIELD_ORIENTATION        15
  133. #define    FIELD_SAMPLESPERPIXEL        16
  134. #define    FIELD_ROWSPERSTRIP        17
  135. #define    FIELD_MINSAMPLEVALUE        18
  136. #define    FIELD_MAXSAMPLEVALUE        19
  137. #define    FIELD_PLANARCONFIG        20
  138. #define    FIELD_PAGENAME            21
  139. #define    FIELD_GROUP3OPTIONS        22
  140. #define    FIELD_GROUP4OPTIONS        23
  141. #define    FIELD_RESOLUTIONUNIT        24
  142. #define    FIELD_PAGENUMBER        25
  143. #define    FIELD_STRIPBYTECOUNTS        26
  144. #define    FIELD_STRIPOFFSETS        27
  145. #define    FIELD_COLORMAP            28
  146. #define FIELD_PREDICTOR            29
  147. #define FIELD_ARTIST            30
  148. #define FIELD_DATETIME            31
  149. #define FIELD_HOSTCOMPUTER        32
  150. #define FIELD_SOFTWARE            33
  151. #define    FIELD_MATTEING            34
  152. #define    FIELD_BADFAXLINES        35
  153. #define    FIELD_CLEANFAXDATA        36
  154. #define    FIELD_BADFAXRUN            37
  155. #define FIELD_SAMPLEFORMAT        38
  156. #define    FIELD_SMINSAMPLEVALUE        39
  157. #define    FIELD_SMAXSAMPLEVALUE        40
  158. #define FIELD_IMAGEDEPTH        41
  159. #define FIELD_TILEDEPTH            42
  160. #define    FIELD_HALFTONEHINTS        43
  161. #ifdef YCBCR_SUPPORT
  162. #define FIELD_YCBCRCOEFFICIENTS        44
  163. #define FIELD_YCBCRSUBSAMPLING        45
  164. #define FIELD_YCBCRPOSITIONING        46
  165. #endif
  166. #ifdef JPEG_SUPPORT
  167. #define FIELD_JPEGPROC            47
  168. #define FIELD_JPEGRESTARTINTERVAL    48
  169. #define FIELD_JPEGQTABLES        49
  170. #define FIELD_JPEGDCTABLES        50
  171. #define FIELD_JPEGACTABLES        51
  172. #endif
  173. #ifdef COLORIMETRY_SUPPORT
  174. #define    FIELD_REFBLACKWHITE        52
  175. #define    FIELD_WHITEPOINT        53
  176. #define    FIELD_PRIMARYCHROMAS        54
  177. #define    FIELD_TRANSFERFUNCTION        55
  178. #endif
  179. #ifdef CMYK_SUPPORT
  180. #define    FIELD_INKSET            56
  181. #define    FIELD_INKNAMES            57
  182. #define    FIELD_DOTRANGE            58
  183. #define    FIELD_TARGETPRINTER        59
  184. #endif
  185. #define    FIELD_LAST            59
  186.  
  187. #define    TIFFExtractData(tif, type, v) \
  188.     ((tif)->tif_header.tiff_magic == TIFF_BIGENDIAN ? \
  189.         ((v) >> (tif)->tif_typeshift[type]) & (tif)->tif_typemask[type] : \
  190.     (v) & (tif)->tif_typemask[type])
  191. #define    TIFFInsertData(tif, type, v) \
  192.     ((tif)->tif_header.tiff_magic == TIFF_BIGENDIAN ? \
  193.         ((v) & (tif)->tif_typemask[type]) << (tif)->tif_typeshift[type] : \
  194.     (v) & (tif)->tif_typemask[type])
  195.  
  196. typedef    struct {
  197.     u_short    field_tag;        /* field's tag */
  198.     short    field_readcount;    /* read count (-1 for unknown) */
  199.     short    field_writecount;    /* write count (-1 for unknown) */
  200.     TIFFDataType field_type;    /* type of associated data */
  201.     u_short    field_bit;        /* bit in fieldsset bit vector */
  202.     u_short    field_oktochange;    /* if true, can change while writing */
  203.     char    *field_name;        /* ASCII name */
  204. } TIFFFieldInfo;
  205.  
  206. #define    FIELD_IGNORE    ((u_short)-1)    /* tags processed but ignored */
  207.  
  208. #define    TIFF_ANY    TIFF_NOTYPE    /* for field descriptor searching */
  209. #define    TIFF_VARIABLE    -1        /* marker for variable length tags */
  210. #define    TIFF_SPP    -2        /* marker for SamplesPerPixel tags */
  211.  
  212. extern    const TIFFFieldInfo tiffFieldInfo[];/* table of field descriptors */
  213. extern    const int tiffDataWidth[];    /* table of tag datatype widths */
  214.  
  215. #define BITn(n)                (((u_long)1L)<<((n)&0x1f)) 
  216. #define BITFIELDn(tif, n)        ((tif)->tif_dir.td_fieldsset[(n)/32]) 
  217. #define TIFFFieldSet(tif, field)    (BITFIELDn(tif, field) & BITn(field)) 
  218. #define TIFFSetFieldBit(tif, field)    (BITFIELDn(tif, field) |= BITn(field))
  219. #define TIFFClrFieldBit(tif, field)    (BITFIELDn(tif, field) &= ~BITn(field))
  220.  
  221. #define    FieldSet(fields, f)        (fields[(f)/32] & BITn(f))
  222. #define    ResetFieldBit(fields, f)    (fields[(f)/32] &= ~BITn(f))
  223.  
  224. /*
  225.  * Typedefs for ``method pointers'' used internally.
  226.  */
  227. #if defined(c_plusplus) || defined(__cplusplus) || defined(__STDC__) || USE_PROTOTYPES
  228. typedef    int (*TIFFVoidMethod)(TIFF*);
  229. typedef    int (*TIFFIOMethod)(TIFF*, u_char*, u_long, u_int);
  230. typedef    int (*TIFFSeekMethod)(TIFF*, u_long);
  231. #else
  232. typedef    int (*TIFFVoidMethod)();
  233. typedef    int (*TIFFIOMethod)();
  234. typedef    long (*TIFFSeekMethod)();
  235. #endif
  236.  
  237. struct tiff {
  238.     char    *tif_name;        /* name of open file */
  239.     short    tif_fd;            /* open file descriptor */
  240.     short    tif_mode;        /* open mode (O_*) */
  241.     char    tif_fillorder;        /* natural bit fill order for machine */
  242.     char    tif_options;        /* compression-specific options */
  243.     short    tif_flags;
  244. #define    TIFF_DIRTYHEADER    0x1    /* header must be written on close */
  245. #define    TIFF_DIRTYDIRECT    0x2    /* current directory must be written */
  246. #define    TIFF_BUFFERSETUP    0x4    /* data buffers setup */
  247. #define    TIFF_BEENWRITING    0x8    /* written 1+ scanlines to file */
  248. #define    TIFF_SWAB        0x10    /* byte swap file information */
  249. #define    TIFF_NOBITREV        0x20    /* inhibit bit reversal logic */
  250. #define    TIFF_MYBUFFER        0x40    /* my raw data buffer; free on close */
  251. #define    TIFF_ISTILED        0x80    /* file is tile, not strip- based */
  252. #define    TIFF_MAPPED        0x100    /* file is mapped into memory */
  253. #define    TIFF_POSTENCODE        0x200    /* need call to postencode routine */
  254.     long    tif_diroff;        /* file offset of current directory */
  255.     long    tif_nextdiroff;        /* file offset of following directory */
  256.     TIFFDirectory tif_dir;        /* internal rep of current directory */
  257.     TIFFHeader tif_header;        /* file's header block */
  258.     const int *tif_typeshift;    /* data type shift counts */
  259.     const long *tif_typemask;    /* data type masks */
  260.     long    tif_row;        /* current scanline */
  261.     int    tif_curdir;        /* current directory (index) */
  262.     int    tif_curstrip;        /* current strip for read/write */
  263.     long    tif_curoff;        /* current offset for read/write */
  264.     long    tif_dataoff;        /* current offset for writing dir */
  265. /* tiling support */
  266.     long     tif_col;        /* current column (offset by row too) */
  267.     int     tif_curtile;        /* current tile for read/write */
  268.     long     tif_tilesize;        /* # of bytes in a tile */
  269. /* compression scheme hooks */
  270.     TIFFVoidMethod    tif_predecode;    /* pre row/strip/tile decoding */
  271.     TIFFVoidMethod    tif_preencode;    /* pre row/strip/tile encoding */
  272.     TIFFVoidMethod    tif_postencode;    /* post row/strip/tile encoding */
  273.     TIFFIOMethod    tif_decoderow;    /* scanline decoding routine */
  274.     TIFFIOMethod    tif_encoderow;    /* scanline encoding routine */
  275.     TIFFIOMethod    tif_decodestrip;/* strip decoding routine */
  276.     TIFFIOMethod    tif_encodestrip;/* strip encoding routine */
  277.     TIFFIOMethod    tif_decodetile;    /* tile decoding routine */
  278.     TIFFIOMethod    tif_encodetile;    /* tile encoding routine */
  279.     TIFFVoidMethod    tif_close;    /* cleanup-on-close routine */
  280.     TIFFSeekMethod    tif_seek;    /* position within a strip routine */
  281.     TIFFVoidMethod    tif_cleanup;    /* routine called to cleanup state */
  282.     char    *tif_data;        /* compression scheme private data */
  283. /* input/output buffering */
  284.     int    tif_scanlinesize;    /* # of bytes in a scanline */
  285.     int    tif_scanlineskew;    /* scanline skew for reading strips */
  286.     char    *tif_rawdata;        /* raw data buffer */
  287.     long    tif_rawdatasize;    /* # of bytes in raw data buffer */
  288.     char    *tif_rawcp;        /* current spot in raw buffer */
  289.     long    tif_rawcc;        /* bytes unread from raw buffer */
  290. /* memory-mapped file support */
  291.     char*    tif_base;        /* base of mapped file */
  292.     long    tif_size;        /* size of mapped file region (bytes) */
  293.     TIFFMapFileProc      tif_mapproc;    /* map file method */
  294.     TIFFUnmapFileProc tif_unmapproc;/* unmap file method */
  295. /* input/output callback methods */
  296.     void    *tif_clientdata;    /* callback parameter */
  297.     TIFFReadWriteProc tif_readproc;    /* read method */
  298.     TIFFReadWriteProc tif_writeproc;/* write method */
  299.     TIFFSeekProc      tif_seekproc;    /* lseek method */
  300.     TIFFCloseProc      tif_closeproc;/* close method */
  301.     TIFFSizeProc      tif_sizeproc;    /* filesize method */
  302. };
  303.  
  304. #define    isTiled(tif)    (((tif)->tif_flags & TIFF_ISTILED) != 0)
  305. #define    isMapped(tif)    (((tif)->tif_flags & TIFF_MAPPED) != 0)
  306. #define    TIFFReadFile(tif, buf, size) \
  307.     ((*(tif)->tif_readproc)((tif)->tif_clientdata, buf, size))
  308. #define    TIFFWriteFile(tif, buf, size) \
  309.     ((*(tif)->tif_writeproc)((tif)->tif_clientdata, buf, size))
  310. #define    TIFFSeekFile(tif, off, whence) \
  311.     ((*(tif)->tif_seekproc)((tif)->tif_clientdata, off, whence))
  312. #define    TIFFCloseFile(tif) \
  313.     ((*(tif)->tif_closeproc)((tif)->tif_clientdata))
  314. #define    TIFFGetFileSize(tif) \
  315.     ((*(tif)->tif_sizeproc)((tif)->tif_clientdata))
  316. #define    TIFFMapFileContents(tif, paddr, psize) \
  317.     ((*(tif)->tif_mapproc)((tif)->tif_clientdata, paddr, psize))
  318. #define    TIFFUnmapFileContents(tif, addr, size) \
  319.     ((*(tif)->tif_unmapproc)((tif)->tif_clientdata, addr, size))
  320.  
  321. /* generic option bit names */
  322. #define    TIFF_OPT0    0x1
  323. #define    TIFF_OPT1    0x2
  324. #define    TIFF_OPT2    0x4
  325. #define    TIFF_OPT3    0x8
  326. #define    TIFF_OPT4    0x10
  327. #define    TIFF_OPT5    0x20
  328. #define    TIFF_OPT6    0x40
  329. #define    TIFF_OPT7    0x80
  330.  
  331. /* NB: the u_long casts are to silence certain ANSI-C compilers */
  332. #ifdef howmany
  333. #undef howmany
  334. #endif
  335. #define    howmany(x, y)    ((((u_long)(x))+(((u_long)(y))-1))/((u_long)(y)))
  336. #ifdef roundup
  337. #undef roundup
  338. #endif
  339. #define    roundup(x, y)    (howmany(x,y)*((u_long)(y)))
  340.  
  341. #if defined(c_plusplus) || defined(__cplusplus) || defined(__STDC__) || USE_PROTOTYPES
  342. #if defined(__cplusplus)
  343. extern "C" {
  344. #endif
  345. extern    void* _TIFFmalloc(size_t);
  346. extern    void* _TIFFrealloc(void*, size_t);
  347. extern    void _TIFFfree(void*);
  348. extern    int _TIFFgetMode(const char* mode, const char* module);
  349. extern    const TIFFFieldInfo *TIFFFindFieldInfo(u_short, TIFFDataType);
  350. extern    const TIFFFieldInfo *TIFFFieldWithTag(u_short);
  351. extern    int _TIFFgetfield(TIFFDirectory*, u_int, ...);
  352. extern    int TIFFNoRowEncode(TIFF*, u_char*, u_long, u_int);
  353. extern    int TIFFNoStripEncode(TIFF*, u_char*, u_long, u_int);
  354. extern    int TIFFNoTileEncode(TIFF*, u_char*, u_long, u_int);
  355. extern    int TIFFNoRowDecode(TIFF*, u_char*, u_long, u_int);
  356. extern    int TIFFNoStripDecode(TIFF*, u_char*, u_long, u_int);
  357. extern    int TIFFNoTileDecode(TIFF*, u_char*, u_long, u_int);
  358. extern    int TIFFFlushData1(TIFF*);
  359. extern    void TIFFFreeDirectory(TIFF*);
  360. extern    int TIFFDefaultDirectory(TIFF*);
  361. extern    int TIFFSetCompressionScheme(TIFF *, int);
  362.  
  363. extern    int TIFFInitDumpMode(TIFF*);
  364. #ifdef PACKBITS_SUPPORT
  365. extern    int TIFFInitPackBits(TIFF*);
  366. #endif
  367. #ifdef CCITT_SUPPORT
  368. extern    int TIFFInitCCITTRLE(TIFF*), TIFFInitCCITTRLEW(TIFF*);
  369. extern    int TIFFInitCCITTFax3(TIFF*), TIFFInitCCITTFax4(TIFF*);
  370. #endif
  371. #ifdef THUNDER_SUPPORT
  372. extern    int TIFFInitThunderScan(TIFF*);
  373. #endif
  374. #ifdef NEXT_SUPPORT
  375. extern    int TIFFInitNeXT(TIFF*);
  376. #endif
  377. #ifdef LZW_SUPPORT
  378. extern    int TIFFInitLZW(TIFF*);
  379. #endif
  380. #ifdef JPEG_SUPPORT
  381. extern    int TIFFInitJPEG(TIFF*);
  382. #endif
  383. #if defined(__cplusplus)
  384. }
  385. #endif
  386. #else /* !USE_PROTOTYPES */
  387. extern    void* _TIFFmalloc();
  388. extern    void* _TIFFrealloc();
  389. extern    void _TIFFfree();
  390. extern    int _TIFFgetMode();
  391. extern    const TIFFFieldInfo *TIFFFindFieldInfo();
  392. extern    const TIFFFieldInfo *TIFFFieldWithTag();
  393. extern    int _TIFFgetfield();
  394. extern    int TIFFNoRowEncode();
  395. extern    int TIFFNoStripEncode();
  396. extern    int TIFFNoTileEncode();
  397. extern    int TIFFNoRowDecode();
  398. extern    int TIFFNoStripDecode();
  399. extern    int TIFFNoTileDecode();
  400. extern    int TIFFFlushData1();
  401. extern    void TIFFFreeDirectory();
  402. extern    int TIFFDefaultDirectory();
  403. extern    int TIFFSetCompressionScheme();
  404.  
  405. extern    int TIFFInitDumpMode();
  406. #ifdef PACKBITS_SUPPORT
  407. extern    int TIFFInitPackBits();
  408. #endif
  409. #ifdef CCITT_SUPPORT
  410. extern    int TIFFInitCCITTRLE(), TIFFInitCCITTRLEW();
  411. extern    int TIFFInitCCITTFax3(), TIFFInitCCITTFax4();
  412. #endif
  413. #ifdef THUNDER_SUPPORT
  414. extern    int TIFFInitThunderScan();
  415. #endif
  416. #ifdef NEXT_SUPPORT
  417. extern    int TIFFInitNeXT();
  418. #endif
  419. #ifdef LZW_SUPPORT
  420. extern    int TIFFInitLZW();
  421. #endif
  422. #ifdef JPEG_SUPPORT
  423. extern    int TIFFInitJPEG();
  424. #endif
  425. #endif /* !USE_PROTOTYPES */
  426. #endif /* _TIFFIOP_ */
  427.